package com.example.springbootserve.service.impl;

import com.example.springbootserve.controller.Request.BaseRquest;
import com.example.springbootserve.entity.Category;
import com.example.springbootserve.mapper.CategoryMapper;
import com.example.springbootserve.service.ICategoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class CategoryService implements ICategoryService {


    @Resource
    CategoryMapper categoryMapper;

    @Override
    public List<Category> list() {
        return categoryMapper.list();
    }

    @Override
    public PageInfo<Category> page(BaseRquest baseRquest) {
        PageHelper.startPage(baseRquest.getPageNum(), baseRquest.getPageSize());
        List<Category> categories = categoryMapper.listByCondition(baseRquest);
        return new PageInfo<>(categories);
    }

    @Override
    public void save(Category obj) {
        categoryMapper.save(obj);
    }

    @Override
    public Category getById(Integer id) {
        return categoryMapper.getById(id);
    }

    @Override
    public void update(Category obj) {
        obj.setUpdatetime(LocalDate.now());
        categoryMapper.updateById(obj);

    }

    @Override
    public void deleteById(Integer id) {
        categoryMapper.deleteById(id);
    }
}
